import { getLevelFirst, getLevelZero, getUserID } from '@/utils';

const NeedlManageTabSwitch = (curRes: Record<string, any>) => {
  const NeedManageTab = () => {
    if (curRes?.['/purchaseNeedController/applyCompanyID']) {
      return {
        applyCompanyID: getLevelZero(),
        params: 'applyCompanyID',
        key: 'NeedManageTabKey',
      };
    } else if (curRes?.['/purchaseNeedController/applyDepartmentID']) {
      return {
        applyDepartmentID: getLevelFirst(),
        params: 'applyDepartmentID',
        key: 'NeedManageTabKey',
      };
    } else if (curRes?.['/purchaseNeedController/applyerID']) {
      return {
        createrID: getUserID(),
        params: 'createrID',
        key: 'NeedManageTabKey',
      };
    }
  };

  const MyNeedCheckTab = () => {
    if (curRes?.['/purchaseNeedController/getMyCheck']) {
      return {
        applyDepartmentID: getLevelFirst(),
        params: 'getMyCheck',
        key: 'NeedCheckTabKey',
        state: 1,
      };
    }
  };

  return [
    {
      title: '需求管理',
      key: 'NeedManageTabKey',
      visible:
        (curRes?.['/purchaseNeedController/applyCompanyID'] ||
          curRes?.['/purchaseNeedController/applyDepartmentID'] ||
          curRes?.['/purchaseNeedController/applyerID']) ??
        false,
      md: 2,
      sm: 24,
      params: NeedManageTab(),
    },
    {
      title: '我的审核',
      key: 'MyNeedCheckTabKey',
      visible: curRes?.['/purchaseNeedController/getMyCheck'] ?? false,
      md: 2,
      sm: 24,
      params: MyNeedCheckTab(),
    },
  ];
};

export const NeedManageTab: any = (curRes: Record<string, any>) => {
  if (curRes?.['/purchaseNeedController/applyCompanyID']) {
    return {
      applyCompanyID: getLevelZero(),
      params: 'applyCompanyID',
    };
  } else if (curRes?.['/purchaseNeedController/applyDepartmentID']) {
    return {
      applyDepartmentID: getLevelFirst(),
      params: 'applyDepartmentID',
    };
  } else if (curRes?.['/purchaseNeedController/applyerID']) {
    return {
      applyerID: getUserID(),
      params: 'applyerID',
    };
  }
};

/**
 * 物料信息权限
 * */
const MaterialManageTab = (curRes: Record<string, any>) => {
  if (curRes?.['/materialController/createCompanyID']) {
    return {
      createCompanyID: getLevelZero(),
      params: 'createCompanyID',
    };
  } else if (curRes?.['/materialController/createDepartmentID']) {
    return {
      createDepartmentID: getLevelFirst(),
      params: 'createDepartmentID',
    };
  } else if (curRes?.['/materialController/createrID']) {
    return {
      createrID: getUserID(),
      params: 'createrID',
    };
  }
};

export { NeedlManageTabSwitch, MaterialManageTab };
